﻿/*  
    Copyright (C) <2007-2013>  <Kay Diefenthal>

    ArgusTv.UI.MediaCenter is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    ArgusTv.UI.MediaCenter is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with ArgusTv.UI.MediaCenter.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections;
using Microsoft.MediaCenter.UI;

namespace ArgusTV.UI.MediaCenter.Views
{
    public class ScheduleEditView : ModelItem
    {
        private IList _commands;
        private Choice _keepUntilModeFilters;
        private EditableText _scheduleName;
        private Choice _schedulePriorityFilters;
        private Choice _scheduleTypeFilters;

        /// <summary>
        ///     The Commands in the view.
        ///     This Commands should only contain object of type Command.
        /// </summary>
        public IList Commands
        {
            get { return _commands; }
            set
            {
                if (_commands != value)
                {
                    _commands = value;
                    FirePropertyChanged("Commands");
                }
            }
        }

        /// <summary>
        ///     The ScheduleName TextBox in the view.
        ///     This EditableText should only contain object of type EditableText.
        /// </summary>
        public virtual EditableText ScheduleName
        {
            get { return _scheduleName; }
            set
            {
                if (_scheduleName != value)
                {
                    if (_scheduleName != null)
                        _scheduleName.Submitted -= OnScheduleNameChanged;
                    _scheduleName = value;
                    if (_scheduleName != null)
                        _scheduleName.Submitted += OnScheduleNameChanged;
                    OnScheduleNameChanged(_scheduleName, EventArgs.Empty);
                    FirePropertyChanged("ScheduleName");
                }
            }
        }

        /// <summary>
        ///     The SchedulePriorityFilters Spinner in the view.
        ///     This SchedulePriorityFilters should only contain objects of type SchedulePriorityFilter.
        /// </summary>
        public virtual Choice SchedulePriorityFilters
        {
            get { return _schedulePriorityFilters; }
            set
            {
                if (_schedulePriorityFilters != value)
                {
                    if (_schedulePriorityFilters != null)
                        _schedulePriorityFilters.ChosenChanged -= OnSchedulePriorityFilterChanged;
                    _schedulePriorityFilters = value;
                    if (_schedulePriorityFilters != null)
                        _schedulePriorityFilters.ChosenChanged += OnSchedulePriorityFilterChanged;
                    OnSchedulePriorityFilterChanged(_schedulePriorityFilters, EventArgs.Empty);
                    FirePropertyChanged("SchedulePriorityFilters");
                }
            }
        }

        /// <summary>
        ///     The ScheduleTypeFilters Spinner in the view.
        ///     This ScheduleTypeFilters should only contain objects of type ScheduleTypeFilter.
        /// </summary>
        public virtual Choice ScheduleTypeFilters
        {
            get { return _scheduleTypeFilters; }
            set
            {
                if (_scheduleTypeFilters != value)
                {
                    if (_scheduleTypeFilters != null)
                        _scheduleTypeFilters.ChosenChanged -= OnScheduleTypeFilterChanged;
                    _scheduleTypeFilters = value;
                    if (_scheduleTypeFilters != null)
                        _scheduleTypeFilters.ChosenChanged += OnScheduleTypeFilterChanged;
                    OnScheduleTypeFilterChanged(_scheduleTypeFilters, EventArgs.Empty);
                    FirePropertyChanged("ScheduleTypeFilters");
                }
            }
        }

        /// <summary>
        ///     The KeepUntilModeFilters Spinner in the view.
        ///     This KeepUntilModeFilters should only contain objects of type KeepUntilModeFilter.
        /// </summary>
        public virtual Choice KeepUntilModeFilters
        {
            get { return _keepUntilModeFilters; }
            set
            {
                if (_keepUntilModeFilters != value)
                {
                    if (_keepUntilModeFilters != null)
                        _keepUntilModeFilters.ChosenChanged -= OnKeepUntilModeFilterChanged;
                    _keepUntilModeFilters = value;
                    if (_keepUntilModeFilters != null)
                        _keepUntilModeFilters.ChosenChanged += OnKeepUntilModeFilterChanged;
                    OnKeepUntilModeFilterChanged(_keepUntilModeFilters, EventArgs.Empty);
                    FirePropertyChanged("KeepUntilModeFilters");
                }
            }
        }

        public event EventHandler ScheduleNameChanged;
        public event EventHandler SchedulePriorityFilterChanged;
        public event EventHandler ScheduleTypeFilterChanged;
        public event EventHandler KeepUntilModeFilterChanged;

        protected virtual void OnScheduleNameChanged(object sender, EventArgs args)
        {
            if (ScheduleNameChanged != null)
                ScheduleNameChanged(this, EventArgs.Empty);
        }

        protected virtual void OnSchedulePriorityFilterChanged(object sender, EventArgs args)
        {
            if (SchedulePriorityFilterChanged != null)
                SchedulePriorityFilterChanged(this, EventArgs.Empty);
        }

        protected virtual void OnScheduleTypeFilterChanged(object sender, EventArgs args)
        {
            if (ScheduleTypeFilterChanged != null)
                ScheduleTypeFilterChanged(this, EventArgs.Empty);
        }

        protected virtual void OnKeepUntilModeFilterChanged(object sender, EventArgs args)
        {
            if (KeepUntilModeFilterChanged != null)
                KeepUntilModeFilterChanged(this, EventArgs.Empty);
        }
    }
}